package org.teremail.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Thin wrapper around sl4j that adds support for formatted logging.
 * 
 * @author Michael Barker
 *
 */
public class Log {

    private Logger dLog;
    
    protected Log(Logger dLog) {
        this.dLog = dLog;
    }
    
    public final void trace(String s) {
        dLog.trace(s);
    }

    public final void trace(Throwable t, String s) {
        dLog.trace(s, t);
    }
    
    public final void trace(String format, Object...params) {
        if (dLog.isTraceEnabled()) {
            trace(String.format(format, params));            
        }
    }
    
    public final void trace(Throwable t, String format, Object...params) {
        if (dLog.isTraceEnabled()) {
            trace(String.format(format, params), t);
        }        
    }
    
    public final void debug(String s) {
        dLog.debug(s);
    }

    public final void debug(Throwable t, String s) {
        dLog.debug(s, t);
    }
    
    public final void debug(String format, Object...params) {
        if (dLog.isDebugEnabled()) {
            debug(String.format(format, params));            
        }
    }
    
    public final void debug(Throwable t, String format, Object...params) {
        if (dLog.isDebugEnabled()) {
            debug(String.format(format, params), t);
        }        
    }
    
    public void info(String s) {
        dLog.info(s);
    }

    public void info(Throwable t, String s) {
        dLog.info(s, t);
    }
    
    public void info(String format, Object...params) {
        if (dLog.isInfoEnabled()) {
            info(String.format(format, params));            
        }
    }
    
    public void info(Throwable t, String format, Object...params) {
        if (dLog.isInfoEnabled()) {
            info(String.format(format, params), t);
        }        
    }
    
    public void warn(String s) {
        dLog.warn(s);
    }

    public void warn(Throwable t, String s) {
        dLog.warn(s, t);
    }
    
    public void warn(String format, Object...params) {
        if (dLog.isWarnEnabled()) {
            warn(String.format(format, params));
        }
    }
    
    public void warn(Throwable t, String format, Object...params) {
        if (dLog.isWarnEnabled()) {
            warn(t, String.format(format, params));
        }
    }
    
    public void error(String s) {
        dLog.error(s);
    }

    public void error(Throwable t, String s) {
        dLog.error(s, t);
    }
    
    public void error(String format, Object...params) {
        if (dLog.isErrorEnabled()) {
            error(String.format(format, params));
        }
    }
    
    public void error(Throwable t, String format, Object...params) {
        if (dLog.isErrorEnabled()) {
            error(t, String.format(format, params));
        }
    }
    
    public static Log getLog(String name) {
        return new Log(LoggerFactory.getLogger(name));
    }
    
    public static Log getLog(Class<?> c) {
        return new Log(LoggerFactory.getLogger(c));
    }

}
